<template>
	<view>
		<view class="search-box">
			<u--input placeholder="搜索" v-model="queryParams.cname" @confirm="search">
				<u-icon name="search" slot="suffix" color="#2979ff" size="28" @click="search"></u-icon>

			</u--input>
		</view>
		<mescroll-body @init="mescrollInit" @down="downCallback" @up="upCallback" :down="downOption" :up="upOption">
			<view class="item_list">
				<!-- <CustomerInfo :data="item" :checkInId.sync="item.checkInId">
				</CustomerInfo> -->
				<view class="item-box" v-for="item in dataList">
					<view class="item">
						<view class="l">
							<view class="title">{{item.customerName}}</view>
							<view class="adress">{{item.currentAddress}}</view>

						</view>
						<view class="r" v-if="item.distance">
							<text>{{item.distance}}米</text>
							<view style="margin-top: 3rpx;">
								<image style="width: 25px; height: 25px;" src="/static/gridManagement/position.png">
								</image>
							</view>
						</view>
					</view>

					<view class="bnts">
						<text class="checkIn" @click="intoCheckIn(item)">{{item.checkInId?'签出':'签到'}}</text>
						<text class="other" @click="detail(item.id)">...</text>


					</view>
				</view>
			</view>

		</mescroll-body>


	</view>
</template>

<script>
	import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";


	import {
		getBadDistributionMap
	} from '@/common/api/performingLoan.js'
	export default {
		mixins: [MescrollMixin],
		components: {

		},
		props: {


		},

		data() {
			return {
				downOption: {
					offset: 80,

				},
				upOption: {
					page: {
						size: 10
					},
					empty: {
						tip: '暂无相关数据'
					}
				},
				dataList: [],
				queryParams: {
					cname: '',
					pageNum: 1,
					pageSize: 10
				}
			}
		},

		methods: {
			search() {
				this.canReset && this.mescroll.scrollTo(0, 0)
				this.canReset && this.mescroll.resetUpScroll()

				this.canReset = true
			},
			detail(id) {
				uni.showToast({
					title: '暂无权限',
					icon: 'none',
					duration: 2000
				});
				return;
				debugger
				uni.navigateTo({
					url: `/pages/performingLoan/detail?id=${id}`
				});
			},
			async intoCheckIn(item) {
				uni.showToast({
					title: '暂无权限',
					icon: 'none',
					duration: 2000
				});
				return;

				let checkInId = item.checkInId ? item.checkInId : null
				if (item.currentAddress && item.currentAddressLonLat) {
					console.log("11111111...................")
					uni.navigateTo({
						url: '/pages/gridManagement/common/checkIn?system=2&id=' + item.id +
							"&longitude=" +
							item.currentAddressLonLat[0] + "&latitude=" + item.currentAddressLonLat[1] +
							"&checkInId=" +
							checkInId + "&address=" + item.currentAddress +
							"&cname=" + item
							.customerName
					});
				} else if (!item.currentAddress) {
					console.log("2222222222222...................")
					uni.showToast({
						title: '请先完善客户地址信息!',
						icon: 'none',
						duration: 2000
					});
				} else {

					let res = await getLatitudeLongitudeByAddress({
						address: item.currentAddress
					})

					let lonLan1 = res.data;


					console.log(lonLan1)
					if (Array.isArray(lonLan1)) {
						uni.navigateTo({
							url: '/pages/gridManagement/common/checkIn?system=2&id=' + item.id +
								"&longitude=" +
								lonLan1[0] + "&latitude=" + lonLan1[1] +
								"&checkInId=" +
								checkInId + "&address=" + item.currentAddress +
								"&cname=" + item
								.customerName
						});

					} else {
						uni.showToast({
							title: '无法定位到该位置!',
							icon: 'none',
							duration: 2000
						});
					}

				}

			},
			async upCallback(page) {
				this.queryParams.pageNum = page.num;
				this.queryParams.pageSize = page.size;
				if (this.queryParams.pageNum == 1) {
					this.dataList = []
				}

				var res = await getBadDistributionMap({
					...this.queryParams

				})



				this.dataList = this.dataList.concat(res.rows);
				this.mescroll.endBySize(this.dataList.length, res.total);
			}
		}
	}
</script>

<style scoped lang="scss">
	.search-box {
		text-align: center;
		padding: 30rpx 70rpx 10rpx;

		::v-deep .u-input {
			border-radius: 10rpx !important;
		}
	}

	.item_list {
		padding: 0 30rpx 30rpx;

		.item-box {
			margin-top: 20rpx;
			// border: 1px solid #ccc;
			overflow: hidden;
			padding: 25rpx 45rpx;
			box-shadow: 0 2px 4px 0 rgba(0, 0, 0, .12), 0 0 6px 0 rgba(0, 0, 0, .04);
			box-shadow: 3px 3px 13px 0 rgba(0, 0, 0, 0.12), -3px -3px 13px 0 rgba(0, 0, 0, 0.12);
			box-shadow: 3px 3px 8px 0 rgba(0, 0, 0, 0.12), -3px 3px 8px 0 rgba(0, 0, 0, 0.12);

			.item {
				overflow: hidden;


				.l {
					float: left;
					width: 80%;

					.title {
						font-size: 30rpx;
						font-weight: 600;
					}

					.adress {
						color: #888888;
						font-size: 25rpx;
						margin: 10rpx 0;
					}
				}

				.r {
					float: right;
					position: relative;
					with: 20%;
					color: #888888;
					padding-top: 25rpx;
					font-size: 25rpx;
				}
			}

			.bnts {
				text-align: center;
				font-size: 18rpx;
				margin-top: 20rpx;

				text {
					padding: 8rpx 24rpx;
					margin: 10rpx 30rpx;
				}

				.checkIn {
					background-color: #92C1F7;
					color: #3D8DE7;
					border-radius: 16rpx;
				}

				.other {
					background-color: #FAE49D;
					color: #FFC300;
					border-radius: 16rpx;
				}
			}


		}
	}
</style>